import { userinfoAPI } from '../axios/api.js'

export default {
  namespaced: true,
  state: {
    username: '',
    token: '',
    userinfo: {}
  },
  mutations: {
    updataToken(state, token) {
      state.token = token
    },
    updataUsername(state, username) {
      state.username = username
    },
    updateUser(state, res) {
      // console.log(res)
      state.userinfo = res
    }
  },
  actions: {
    async getUser(ctx) {
      const { data: res } = await userinfoAPI()
      // console.log(res)
      if (res.code === 0) {
        // console.log(res.data)
        ctx.commit('updateUser', res.data)
      }
    }
  }
}
